﻿using UnityEngine;
using System.Collections;



public class CameraScript: MonoBehaviour {
	
	private float maxDistance;
	private float minDistance;
	private float zoom;
	private Vector3 target;
	
	
	
	
	
	// Use this for initialization
	
	void Start () {
		
		target = Vector3.zero;
		
		zoom = 1.0f;
		
		maxDistance = 50.0f;
		minDistance = 1.0f;
		
		
		
		
		
	}
	
	
	
	// Update is called once per frame
	
	void Update () {
		
		camera.transform.LookAt(target);
		Ray ray = new Ray(transform.position, transform.forward);
		if(Input.GetAxis("Mouse ScrollWheel") != 0){
			if(Input.GetAxis("Mouse ScrollWheel") > 0){
				
				Debug.Log("close");
				
				if(Vector3.Distance(transform.position, target) > minDistance)
					
					camera.transform.position = ray.GetPoint(zoom);
				
			}
			
			if(Input.GetAxis("Mouse ScrollWheel") < 0){
				Debug.Log("far");
				if(Vector3.Distance(transform.position, target) < maxDistance)
					camera.transform.position = ray.GetPoint(-zoom);
				
			}
			
		}
		
	}
	
}